package com.ruoyi.mdkt.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.mdkt.entity.Absent;
import com.ruoyi.mdkt.entity.Course;
import com.ruoyi.mdkt.entity.Student;
import com.ruoyi.mdkt.entity.Teacher;
import com.ruoyi.mdkt.entity.vo.AbsentVo;
import com.ruoyi.mdkt.entity.vo.CourseVo;
import com.ruoyi.mdkt.entity.vo.ShowAbsentVo;
import com.ruoyi.mdkt.service.AbsentService;
import com.ruoyi.mdkt.service.StudentService;
import com.ruoyi.mdkt.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gwl
 * @since 2022-10-25
 */

@CrossOrigin
@RestController
@RequestMapping("/mdkt/absent")
public class AbsentController {

    @Autowired
    private AbsentService absentService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentService studentService;


    @GetMapping("/pageAbsent/{courseId}")
    public R pageAbsent(@PathVariable("courseId") Long courseId) {
        List<AbsentVo> list = absentService.getAbsentList(courseId);
        return R.ok(list);
    }


    @GetMapping("/infoAbsent/{absentId}")
    public R infoAbsent(@PathVariable("absentId") Long absentId) {
        AbsentVo absentInfo = absentService.getAbsentInfo(absentId);
        return R.ok(absentInfo);
    }

    @PostMapping("/save")
    public R<String> save(@RequestBody Absent absent) {
        absent.setIsAllowed(2);
        absentService.save(absent);
        return R.ok();
    }

    @PostMapping("/findQueryPage/{pageNum}/{pageSize}")
    public R<Page<ShowAbsentVo>> pageList(@RequestBody(required = false) Absent searchObj, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        Page<ShowAbsentVo> page = absentService.pageList(searchObj, pageNum, pageSize);
        return R.ok(page);
    }



}

